﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PreeRegisterModel;
using System.Data;
using PreeRegisterDAL;

namespace PreeRegisterBLL
{
    public class PacsReportBLL
    {

        /// <summary>
        /// 检查报告列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static PacsReportListResponseModel GetPacsReportList(PacsReportListRequestModel request)
        {
            try
            {
                //查询检验报告列表
                PacsReportListResponseModel PacsReportListResponseModel = new PreeRegisterModel.PacsReportListResponseModel();

                //查询患者检查处方单号
                string billcode = PacsReportDAL.Getbillcode(request.cpatientcode);

                DataSet ds = PacsReportDAL.GetPacsReportList(billcode);

                //获取检验报告列表
                List<PacsReportListItemResponseModel> PacsbReportListItemResponseModel_list = new List<PacsReportListItemResponseModel>();

                foreach (DataRow drPacsReport in ds.Tables[0].Rows)
                {
                    PacsReportListItemResponseModel PacsReportListItemResponseModel = new PacsReportListItemResponseModel();
                    PacsReportListItemResponseModel.ApplyNo = drPacsReport["ApplyNo"].ToString();
                    PacsReportListItemResponseModel.cjgsj = drPacsReport["cjgsj"].ToString();
                    PacsReportListItemResponseModel.MainID = drPacsReport["MainID"].ToString();
                    PacsReportListItemResponseModel.OrderNo = drPacsReport["OrderNo"].ToString();
                    PacsReportListItemResponseModel.ReportTypeName = drPacsReport["ReportTypeName"].ToString();
                    PacsReportListItemResponseModel.TestSample = drPacsReport["TestSample"].ToString();

                    PacsbReportListItemResponseModel_list.Add(PacsReportListItemResponseModel);
                }

                PacsReportListResponseModel.reportlist = PacsbReportListItemResponseModel_list;

                //返回
                return PacsReportListResponseModel;
            }
            catch (Exception err)
            {

                throw;
            }
        }

        /// <summary>
        /// 检查报告明细
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static PacsReportDetailResponseModel GetPacsReportDetail(PacsReportDetailRequestModel request)
        {
            try
            {
                //查询检验报告明细
                PacsReportDetailResponseModel PacsReportDetailResponseModel = new PreeRegisterModel.PacsReportDetailResponseModel();

                DataSet ds = PacsReportDAL.GetPacsReportDetail(request.mainid);

                if (ds == null)
                {
                    return null;
                }

                //获取检验报告结果

                
                
                PacsReportDetailResponseModel.jysj = ds.Tables[0].Rows[0]["jysj"].ToString();
                PacsReportDetailResponseModel.mainid = ds.Tables[0].Rows[0]["mainid"].ToString();
                PacsReportDetailResponseModel.Name = ds.Tables[0].Rows[0]["Name"].ToString();
                PacsReportDetailResponseModel.SectionOffice = ds.Tables[0].Rows[0]["SectionOffice"].ToString();
                PacsReportDetailResponseModel.ApplyNo = ds.Tables[0].Rows[0]["ApplyNo"].ToString();
                PacsReportDetailResponseModel.TestSample = ds.Tables[0].Rows[0]["TestSample"].ToString();

                List<PacsReportDetailItemResponseModel> PacsReportDetailItemResponseModel_list = new List<PacsReportDetailItemResponseModel>();

                for (int i = 0; i < 4;i++ )
                {
                    if (i == 0)
                    {
                        if (ds.Tables[0].Rows[0]["TITLEONE"].ToString().Trim() == "")
                        {
                            PacsReportDetailResponseModel.detail = PacsReportDetailItemResponseModel_list;
                            return PacsReportDetailResponseModel;
                        } 
                        PacsReportDetailItemResponseModel PacsReportDetailItemResponseModel = new PacsReportDetailItemResponseModel();
                        PacsReportDetailItemResponseModel.TestItemChi = ds.Tables[0].Rows[0]["TITLEONE"].ToString();
                        PacsReportDetailItemResponseModel.TestResult = ds.Tables[0].Rows[0]["CONTENTONE"].ToString();
                        PacsReportDetailItemResponseModel_list.Add(PacsReportDetailItemResponseModel);
                    }
                    if (i == 1)
                    {
                        if (ds.Tables[0].Rows[0]["TITLETWO"].ToString().Trim() == "")
                        {
                            PacsReportDetailResponseModel.detail = PacsReportDetailItemResponseModel_list;
                            return PacsReportDetailResponseModel;
                        }  
                        PacsReportDetailItemResponseModel PacsReportDetailItemResponseModel = new PacsReportDetailItemResponseModel();
                        PacsReportDetailItemResponseModel.TestItemChi = ds.Tables[0].Rows[0]["TITLETWO"].ToString();
                        PacsReportDetailItemResponseModel.TestResult = ds.Tables[0].Rows[0]["CONTENTTWO"].ToString();
                        PacsReportDetailItemResponseModel_list.Add(PacsReportDetailItemResponseModel);
                    }
                    if (i == 2)
                    {
                        if (ds.Tables[0].Rows[0]["TITLETHREE"].ToString().Trim() == "")
                        {
                            PacsReportDetailResponseModel.detail = PacsReportDetailItemResponseModel_list;
                            return PacsReportDetailResponseModel;
                        }
                        PacsReportDetailItemResponseModel PacsReportDetailItemResponseModel = new PacsReportDetailItemResponseModel();
                        PacsReportDetailItemResponseModel.TestItemChi = ds.Tables[0].Rows[0]["TITLETHREE"].ToString();
                        PacsReportDetailItemResponseModel.TestResult = ds.Tables[0].Rows[0]["CONTENTTHREE"].ToString();
                        PacsReportDetailItemResponseModel_list.Add(PacsReportDetailItemResponseModel);
                    }
                    if (i == 3)
                    {
                        if (ds.Tables[0].Rows[0]["TITLEFOUR"].ToString().Trim() == "")
                        {
                            PacsReportDetailResponseModel.detail = PacsReportDetailItemResponseModel_list;
                            return PacsReportDetailResponseModel;
                        }
                        PacsReportDetailItemResponseModel PacsReportDetailItemResponseModel = new PacsReportDetailItemResponseModel();
                        PacsReportDetailItemResponseModel.TestItemChi = ds.Tables[0].Rows[0]["TITLEFOUR"].ToString();
                        PacsReportDetailItemResponseModel.TestResult = ds.Tables[0].Rows[0]["CONTENTFOUR"].ToString();
                        PacsReportDetailItemResponseModel_list.Add(PacsReportDetailItemResponseModel);
                    }
                    
                }

                PacsReportDetailResponseModel.detail = PacsReportDetailItemResponseModel_list;

                //返回
                return PacsReportDetailResponseModel;
            }
            catch (Exception err)
            {

                throw;
            }
        }
    }
}
